<?php

namespace register\view;

require_once("common/model/User.php");

class RegisterView {

	private static $USERNAME = "RegisterView::Username";
	private static $PASSWORD = "RegisterView::Password";
	private static $REPEATPASSWORD = "RegisterView::RepeatPassword";
	private static $SUBMIT = "RegisterView::Submit";
	private static $REMEMBER = "RegisterView::Remember";

	private $message;

	/**
	 * @return string html
	 */
	public function RegisterHTMLForm() {
		$username = $this->getUsername();
		$html = 
		"<div id='registerForm'>
			<form action='' method='post' enctype='multipart/form-data'>				
				<fieldset>
					<p>$this->message</p>
					<legend>Register</legend>
					<input id='UsernameID' placeholder='Username' name='".self::$USERNAME."'/> 
					<input id='PasswordID' placeholder='Password' type='password' value='' name='".self::$PASSWORD."'/>
					<input id='SubmitID' type='submit' value='Register' name='".self::$SUBMIT."'/> 
				</fieldset>
			</form>
		</div>";
		return $html;
	}

	/**
	 * if registration fail, show appropriate message
	 * @return void
	 */
	public function registerFail() {
		if ($this->getUsername() == "") {
			$this->message = "Username needs to be atleast 3 characters.</p>";
		} else if ($this->getPassword() == "") {
			$this->message = "Password is too short. Needs to be atleast 4 characters.</p>";
		} else {
			$this->message = "Username is already exist<";
		}
	}

	/**
	 * gets posted data and returns a User object
	 * @return \register\model\User
	 */
	public function getUserData() {
		$username = strip_tags($this->getUsername());
		$password = $this->getPassword();
		return new \common\model\User($username, $password);
	}

	/**
	 * if user is registrating return true
	 * @return bool
	 */
	public function userRegistrating() {
		if (isset($_POST[self::$SUBMIT])) {
			return true;
		}
		return false;
	}

	/**
	 * @return string
	 */
	public function getUsername() {
		if (isset($_POST[self::$USERNAME])) {
			return $_POST[self::$USERNAME];
		}
	}

	/**
	 * @return string
	 */
	public function getPassword() {
		if (isset($_POST[self::$PASSWORD])) {
			return $_POST[self::$PASSWORD];
		}
	}
}